Skip to content

fix: preserve NULL semantics in log and power simplification - #24247

Merged
Jefffrey merged 1 commit into
apache:mainfrom
lyne7-sc:fix-log-power-nullable-simplification
Aug 12, 2026
Merged

fix: preserve NULL semantics in log and power simplification#24247
Jefffrey merged 1 commit into
apache:mainfrom
lyne7-sc:fix-log-power-nullable-simplification

Conversation

@lyne7-sc

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

log and power simplifications removed a nullable base expression, which could incorrectly produce a non-NULL result when the base was NULL.

For example:

SELECT log(a, 1.0), power(a, 0.0)
FROM (VALUES (NULL::DOUBLE)) AS t(a);

These expressions should both return NULL, but simplification could replace them with 0.0 and 1.0.

What changes are included in this PR?

only apply these simplifications when the removed base expression is non-nullable.

Are these changes tested?

Yes. Added sqllogictests covering results and plans.

Are there any user-facing changes?

Yes. log and power expressions with nullable bases now correctly preserve NULLs.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Aug 11, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.01%. Comparing base (4b48cb0) to head (3a74506).
⚠️ Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/functions/src/math/log.rs 71.42% 0 Missing and 2 partials ⚠️
datafusion/functions/src/math/power.rs 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24247      +/-   ##
==========================================
- Coverage   81.06%   81.01%   -0.05%     
==========================================
  Files        1106     1106              
  Lines      382252   383982    +1730     
  Branches   382252   383982    +1730     
==========================================
+ Hits       309861   311080    +1219     
- Misses      54083    54561     +478     
- Partials    18308    18341      +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lyne7-sc

@Jefffrey
Jefffrey added this pull request to the merge queue Aug 12, 2026
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @lyne7-sc & @alamb

Merged via the queue into apache:main with commit c08832d Aug 12, 2026
37 checks passed
kosiew pushed a commit to kosiew/datafusion that referenced this pull request Aug 12, 2026
…che#24247)

## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

- Part of apache#24246.

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.

Please explain the problem you are trying to solve in terms of the
user-visible
behavior, rather than the implementation.

For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of
the
implementation. "COUNT(DISTINCT) returns wrong results when the column
contains
nulls" is the user-visible problem.
-->

`log` and `power` simplifications removed a nullable base expression,
which could incorrectly produce a non-NULL result when the base was
NULL.

For example:

```sql
SELECT log(a, 1.0), power(a, 0.0)
FROM (VALUES (NULL::DOUBLE)) AS t(a);
```

These expressions should both return NULL, but simplification could
replace them with 0.0 and 1.0.

## What changes are included in this PR?

only apply these simplifications when the removed base expression is
non-nullable.

<!--
There is no need to duplicate the description in the issue here, but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

## Are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

Yes. Added sqllogictests covering results and plans.

## Are there any user-facing changes?

Yes. log and power expressions with nullable bases now correctly
preserve NULLs.

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.

If there are any breaking changes to public APIs, please add the `api
change` label.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants